const edit = {
  props:{
    
  },
  data(){
    return {
      isShow: false,
      title: null,
      btnLoading: false,
      params: null,
      form:{
        // "id": null,
        "name": null,
        "code": null,
        "county": null,
        "town": null,
        "address": null,
        "lon": null,
        "lat": null,
        "indcode_level4": null,
        "ent_type": null,
        "collection_type": null,
        "so2_tech": null,
        "nox_tech": null,
        "pm_tech": null,
        "vocs_tech": null,
        "vocs_type": null,
        "production_lines_vocs": null,
        "scale_furnace/boiler": null,
        "num_furnace/boiler": null,
        "chimney_height": null,
        "chimney_diameter": null,
        "so2": null,
        "nox": null,
        "vocs": null,
        "pm10": null,
        "pm25": null,
        "measures2_pm": null,
        "measures2_nox": null,
        "measures2_o3": null,
        "measures3_pm": null,
        "measures3_nox": null,
        "measures3_o3": null,
        "pic": null,
        "update_time": null,
        "indtype_level2": null,
        "indcode_level2": null,
        "indtype_level4": null,
        "geom": null,
        "city_pos": null,
        "last_editor": null,
        "class": null,
        "voc_level": null,
        "furnace_level": null,
        "contact": null,
        "telephone": null,
        "area_dust": null
      },
      defaultFrom: null,
      type: 'add',
      api: '/stations/ind',
      indLabel: null,
      initData:{},
    }
  },
  created(){
    this.defaultForm = JSON.parse(JSON.stringify(this.form));
  },
  methods:{
    init(params, type){
      console.log(params, type);
      this.type = type;
      this.initData = JSON.parse(JSON.stringify(this.$parent.$parent.initData));
      this.initData.countys.shift();           
      if(type == 'add'){
        this.title = '新增污染源';
        this.api = '/stations/ind_add'
      }else{
        this.params = JSON.parse(JSON.stringify(params));
        this.$util.resetForm(this.form, params);
        if(this.form.update_time){
          this.form.update_time = this.$moment(this.form.update_time).format('YYYY-MM-DD HH:mm:ss')
        }
        this.form.id = params.id;
        this.title = params.name;
        this.api = '/stations/ind';
      }
      this.initCallback(); 
      this.isShow = true;
    },
    initCallback(){

    },
    changeEmissions(val, type){
      if(val){
        this.form[type] = Number(val).toFixed(2);
      }      
    },
    closeDrawer(){
      this.form = JSON.parse(JSON.stringify(this.defaultForm));
      this.indLabel = null;
      this.$emit('close')
    },
    verifyForm(){
      if(!this.$verify.null(this.form.name, '请填写污染源名称')){
        return false;
      }
      //经度[113-115]
      if(Number(this.form.lon) < 113 || Number(this.form.lon) > 115){
        this.$message.warning('经度须在113-115之间')
        return false;
      }
      //纬度[21-23]
      if(Number(this.form.lat) < 21 || Number(this.form.lat) > 23){
        this.$message.warning('纬度须在21-23之间')
        return false;
      }
      if(!this.$verify.null(this.form.county, '请选择所属区县')){
        return false;
      }
      return true;
    },
    submitForm(){
      if(!this.verifyForm()){
        return;
      }
      if(JSON.stringify(this.params) == JSON.stringify(this.form)){
        this.isShow = false;
        return;
      }else{
        this.form.update_time = this.$moment().format('YYYY-MM-DD HH:mm:ss');
        this.form.last_editor = this.$store.getters.currentUser;
      }
      let params = this.$util.filterNull(this.form);
      this.btnLoading = true;
      this.$request('post', this.api, params, (data,msg) => {
        if(data.msg == '更新成功' || data.msg == '添加成功'){
          this.$message.success(data.msg);      
          this.isShow = false;
          this.$emit('save');
        }else{
          this.$message.error(data.msg);          
        }
        this.btnLoading = false;
      },msg => {
        this.btnLoading = false;
      })

    },
  }
}

export default edit;